package com.pet.petadoption.petstorage.biz.impl;

import com.pet.petadoption.adoption.entity.Adoption;
import com.pet.petadoption.pet.entity.Pet;
import com.pet.petadoption.petstorage.biz.PetstorageBiz;
import com.pet.petadoption.petstorage.entity.Petstorage;
import com.pet.petadoption.petstorage.mapper.PetstorageMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class PetstorageBizImpl implements PetstorageBiz {
    @Resource
    PetstorageMapper petstorageMapper;

    @Override
    public List<Petstorage> findAll(Integer index, Integer size, Boolean isAdopted) {

        //        计算上一页最后一条数据
        int newIndex = (index-1)*size;
        Map<String,Object> map = new HashMap<>();
        map.put("index" ,newIndex);
        map.put("size",size);
        map.put("isAdopted",isAdopted);
        return petstorageMapper.findAll(map);
    }

    @Override
    public Boolean delById(Integer id) {
        return petstorageMapper.delById(id);
    }

    @Override
    public Petstorage findById(Integer id, Boolean isAdopted) {
        Map<String,Object> map = new HashMap<>();
        map.put("id" ,id);
        map.put("isAdopted",isAdopted);
        return petstorageMapper.findById(map);
    }

    @Override
    public List<Petstorage> findByUname(String uname, Boolean isAdopted) {
         Map<String,Object> map = new HashMap<>();
        map.put("uname" ,uname);
        map.put("isAdopted",isAdopted);
        return petstorageMapper.findByUname(map);
    }

    @Override
    public Integer delArr(String ids) {
        return petstorageMapper.delArr(ids);
    }

    @Override
    public Boolean addStorage(Petstorage petstorage) {
        return petstorageMapper.addStorage(petstorage);
    }

    @Override
    public Pet getPetId(Pet pet) {
        return petstorageMapper.getId(pet);
    }

    @Override
    public Integer accessPetStroage(Integer id) {
        return petstorageMapper.accessPetStroage(id);
    }
}
